﻿<?php
session_start();
/**
 * @author gnzlo
 * @copyright 2009
 */
include ("Combo.php");
include ("ComboAlumno.php");
include ("classConexionBD.php");

class LoginServices
{
    public $userProfile;
    public $conectar;
    public $armar;
    public function doLogIn($usuario, $password)
    {
        $conectar = new ConexionBD();
        $conectar->conectar();
        $query = "SELECT persona.id AS id, persona.nombre AS nombre, persona.apellido AS apellido, persona.usuario AS user, persona.contrasena AS pass, persona.tipo AS perfil 
		FROM persona
		where persona.usuario='" . $usuario . "' and persona.contrasena='" . $password ."'";

        $conectar->enviarQuery($query);
        $log = $conectar->resultadoQuery();

        if ($usuario == $log[0]['user'] && $password == $log[0]['pass']) {
            $datos = $log;
            return $this->returnPerfil($datos, $conectar, $query); //funcion q completa el perfil

        } else {
            return false;
        }

    }

    private function returnPerfil($infoUser, $unaConexion, $unQuery)
    {
        switch ($infoUser[0]['perfil']) {

            case 1:
                /*PERFIL ESTUDIANTE */
                $armar = new ComboAlumno($unaConexion, $infoUser[0]['user'], $infoUser[0]['pass']);
                $arr[]=array('perfil'=>$armar->perfil(), 'studentCareerSignatures'=>$armar->careerReceiverVO());
                return $arr;
                break;

                /*PERFIL DOCENTE*/
            case 2:

                $armar = new Combo($unaConexion, $infoUser[0]['user'], $infoUser[0]['pass']);
                $arr[]=array('perfil'=>$armar->perfil(), 'careerReceiverVO'=>$armar->careerReceiverVO(), 'pautas'=>$armar->pautasGuardadas());
                return $arr;
                break;
        }


    }

}

?>